<template>
  <view>
    <view class="address-choose" v-if="JSON.stringify(address) === '{}'">
      <button type="primary" size="mini" class="btn-choose" @click="chooseAddress">请选择收获地址</button>
    </view>
    <view class="address-info" v-else @click="chooseAddress">
      <view class="row1">
        <view class="username">收货人：{{address.userName}}</view>
        <view class="phone">
          <text>电话：{{address.telNumber}}</text>
          <uni-icons type="arrowright"></uni-icons>
        </view>
      </view>
      <view class="row2">
        <view class="text">收货地址：</view>
        <view class="addressDetail">{{addstr}}</view>
      </view>
    </view>
    <image src="/static/cart_border@2x.png" class="address-border"></image>
  </view>
</template>

<script>
  import { mapState,mapMutations,mapGetters} from 'vuex'
  export default {
    name:"my-address",
    data() {
      return {
        
      };
    },
    methods:{
      ...mapMutations('user',['updateAddress']),
      async chooseAddress(){
        const [err,succ] = await uni.chooseAddress().catch(err => err)
        if(err === null && succ.errMsg === 'chooseAddress:ok'){
          this.updateAddress(succ)
        }
      }
    },
    computed:{
      ...mapState('user',['address']),
      ...mapGetters('user',['addstr'])
    }
  }
</script>

<style lang="scss">
.address-border{
  display: block;
  width: 100%;
  height: 5px;
}
.address-choose{
  height: 90px;
  display: flex;
  justify-content: center;
  align-items: center;
}
.address-info{
  height: 90px;
  font-size: 12px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 0 5px;
  .row1{
    display: flex;
    justify-content: space-between;
    .phone{
      display: flex;
      align-items: center;
    }
  }
  .row2{
    display: flex;
    align-items: center;
    margin-top: 10px;
  }
}
</style>